function $(id) {
	return document.getElementById(id);
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function changechecked(selected, prefix)
{
	inputs = document.getElementsByTagName("input");
	for(var index = 0; index < inputs.length; index++)
	{
		items = inputs[index].name.split("_");
		if(items.length >= 2)
		{
			if (items[0] == prefix)
			{
				inputs[index].checked = selected;
			}
		}
	}
}

function addmoreitem()
{
	ul = $("photofieldlist")
	if(ul)
	{
		items = ul.getElementsByTagName('li');
		if(items.length > 0)
		{
			lastone = items[items.length -1];
			newone = lastone.cloneNode(true);
			if(newone)
			{
				ul.appendChild(newone);
			}
		}
	}
}

function selectallmtg()
{
	changechecked(true, "mtg");
}

function selectalliphone()
{
	changechecked(true, "iphone");
}

function selectalliphonefree()
{
	changechecked(true, "iphonefree");
}

function clearallmtg()
{
	changechecked(false, "mtg");
}

function clearalliphone()
{
	changechecked(false, "iphone");
}

function clearalliphonefree()
{
	changechecked(false, "iphonefree");
}